package domain.shop;

import domain.AbstractEntity;
import domain.Address;
import domain.User;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Table(name = "CUSTOMER_ORDER")
@Entity
public class Order extends AbstractEntity {

    @OneToMany
    @Cascade(CascadeType.ALL)
    List<BasketItem> products = new ArrayList<BasketItem>();
    @OneToOne
    Address deliveryAddress;
    @OneToOne
    DeliveryMethod deliveryMethod;
    @OneToOne
    PayMethod payMethod;
    @ManyToOne
    private User user;
    @Column(name = "CREATE_TS")
    Date date = new Date(new java.util.Date().getTime());
    BigDecimal totalPrice;
    boolean active = true;
    boolean processed;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Order() {
    }

    public boolean removeBasketItem(BasketItem o) {
        return products.remove(o);
    }

    public boolean isProcessed() {
        return processed;
    }

    public void setProcessed(boolean processed) {
        this.processed = processed;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Address getDeliveryAddress() {
        return deliveryAddress;
    }

    public void setDeliveryAddress(Address deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public PayMethod getPayMethod() {
        return payMethod;
    }

    public void setPayMethod(PayMethod payMethod) {
        this.payMethod = payMethod;
    }

    public DeliveryMethod getDeliveryMethod() {
        return deliveryMethod;
    }

    public void setDeliveryMethod(DeliveryMethod deliveryMethod) {
        this.deliveryMethod = deliveryMethod;
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public List<BasketItem> getProducts() {
        return products;
    }

    public void setProducts(List<BasketItem> products) {
        this.products = products;
    }
}

